<template>
    <el-container class="con_container">
      <el-header>
        <div class="logotitle">
          <img src="../assets/heima.png">
          <span style="padding-left: 20px">后台管理</span>
        </div>
        <el-button size="mini" round @click="logout">注销</el-button>

      </el-header>
      <el-container>

<!--        左側菜單-->
        <el-aside  class="con_aside" :width="collapseList ? '64px' : '200px'">
          <div class="yincang" @click="yincang">
            |||
          </div>
<!--          菜單導航-->
          <el-menu background-color="#333744" text-color="#fff" :unique-opened="true" :collapse-transition = "false" :collapse = collapseList router>
<!--            一級菜單-->
            <el-submenu :index="item.id+''"  v-for="item in menuList.data" :key="item.id">
              <template slot="title">
                <i class="el-icon-star-off"></i>
                <span>{{ item.authName }}</span>
              </template>
<!--              二級菜單-->
              <el-menu-item :index="'/'+childitem.path" v-for="childitem in item.children" :key="childitem.id">
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{ childitem.authName }}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main class="con_main">
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
</template>

<script>
export default {
  name: 'home',
  data () {
    return {
      menuList: [],
      collapseList: false
    }
  },
  created() {
    this.loadMenuList()
  },
  methods: {
    logout() {
      window.sessionStorage.removeItem('token')
      this.$router.push('/login')
    },
    async loadMenuList() {
      const { data: res } = await this.$http.get('menus')
      this.menuList = res
      // console.log(this.menuList)
    },
    yincang() {
      this.collapseList = !this.collapseList
    }
  }
}
</script>

<style scoped>
  .con_container{
    height: 100%;
  }
  .logotitle{
    color: #ffffff;
    padding-left: 0px;
    font-size: 20px;
    line-height: 100%;
    display: flex;
    align-items: center;
  }
  .el-header{
    display: flex;
    justify-content: space-between;
    background-color: #373d41;
    align-items: center;
  }
  .con_aside{
    background-color: #333744;
    color: #ffffff;
  }
  .con_main{
    background-color: #eaedf1;
  }
  .yincang{
    text-align: center;
    letter-spacing: 3px;
    cursor: pointer;
  }
  .el-menu{
    border-right:0;
  }
</style>
